// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"server/components/models/ent/region"
	"server/components/models/ent/weather"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
)

// Weather is the model entity for the Weather schema.
type Weather struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// Temperature holds the value of the "temperature" field.
	Temperature float64 `json:"temperature,omitempty"`
	// Humidity holds the value of the "humidity" field.
	Humidity float64 `json:"humidity,omitempty"`
	// WindSpeed holds the value of the "windSpeed" field.
	WindSpeed float64 `json:"windSpeed,omitempty"`
	// WeatherCondition holds the value of the "weatherCondition" field.
	WeatherCondition weather.WeatherCondition `json:"weatherCondition,omitempty"`
	// PrecipitationAmount holds the value of the "precipitationAmount" field.
	PrecipitationAmount float64 `json:"precipitationAmount,omitempty"`
	// MeasurementDateTime holds the value of the "measurementDateTime" field.
	MeasurementDateTime time.Time `json:"measurementDateTime,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the WeatherQuery when eager-loading is set.
	Edges          WeatherEdges `json:"edges"`
	weather_region *int64
	selectValues   sql.SelectValues
}

// WeatherEdges holds the relations/edges for other nodes in the graph.
type WeatherEdges struct {
	// Region holds the value of the region edge.
	Region *Region `json:"region,omitempty"`
	// Forecast holds the value of the forecast edge.
	Forecast []*Forecast `json:"forecast,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [2]bool
}

// RegionOrErr returns the Region value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e WeatherEdges) RegionOrErr() (*Region, error) {
	if e.Region != nil {
		return e.Region, nil
	} else if e.loadedTypes[0] {
		return nil, &NotFoundError{label: region.Label}
	}
	return nil, &NotLoadedError{edge: "region"}
}

// ForecastOrErr returns the Forecast value or an error if the edge
// was not loaded in eager-loading.
func (e WeatherEdges) ForecastOrErr() ([]*Forecast, error) {
	if e.loadedTypes[1] {
		return e.Forecast, nil
	}
	return nil, &NotLoadedError{edge: "forecast"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Weather) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case weather.FieldTemperature, weather.FieldHumidity, weather.FieldWindSpeed, weather.FieldPrecipitationAmount:
			values[i] = new(sql.NullFloat64)
		case weather.FieldID:
			values[i] = new(sql.NullInt64)
		case weather.FieldWeatherCondition:
			values[i] = new(sql.NullString)
		case weather.FieldMeasurementDateTime:
			values[i] = new(sql.NullTime)
		case weather.ForeignKeys[0]: // weather_region
			values[i] = new(sql.NullInt64)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Weather fields.
func (w *Weather) assignValues(columns []string, values []any) error {
	if m, n := len(values), len(columns); m < n {
		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
	}
	for i := range columns {
		switch columns[i] {
		case weather.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			w.ID = int64(value.Int64)
		case weather.FieldTemperature:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field temperature", values[i])
			} else if value.Valid {
				w.Temperature = value.Float64
			}
		case weather.FieldHumidity:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field humidity", values[i])
			} else if value.Valid {
				w.Humidity = value.Float64
			}
		case weather.FieldWindSpeed:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field windSpeed", values[i])
			} else if value.Valid {
				w.WindSpeed = value.Float64
			}
		case weather.FieldWeatherCondition:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field weatherCondition", values[i])
			} else if value.Valid {
				w.WeatherCondition = weather.WeatherCondition(value.String)
			}
		case weather.FieldPrecipitationAmount:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field precipitationAmount", values[i])
			} else if value.Valid {
				w.PrecipitationAmount = value.Float64
			}
		case weather.FieldMeasurementDateTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field measurementDateTime", values[i])
			} else if value.Valid {
				w.MeasurementDateTime = value.Time
			}
		case weather.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for edge-field weather_region", value)
			} else if value.Valid {
				w.weather_region = new(int64)
				*w.weather_region = int64(value.Int64)
			}
		default:
			w.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

// Value returns the ent.Value that was dynamically selected and assigned to the Weather.
// This includes values selected through modifiers, order, etc.
func (w *Weather) Value(name string) (ent.Value, error) {
	return w.selectValues.Get(name)
}

// QueryRegion queries the "region" edge of the Weather entity.
func (w *Weather) QueryRegion() *RegionQuery {
	return NewWeatherClient(w.config).QueryRegion(w)
}

// QueryForecast queries the "forecast" edge of the Weather entity.
func (w *Weather) QueryForecast() *ForecastQuery {
	return NewWeatherClient(w.config).QueryForecast(w)
}

// Update returns a builder for updating this Weather.
// Note that you need to call Weather.Unwrap() before calling this method if this Weather
// was returned from a transaction, and the transaction was committed or rolled back.
func (w *Weather) Update() *WeatherUpdateOne {
	return NewWeatherClient(w.config).UpdateOne(w)
}

// Unwrap unwraps the Weather entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (w *Weather) Unwrap() *Weather {
	_tx, ok := w.config.driver.(*txDriver)
	if !ok {
		panic("ent: Weather is not a transactional entity")
	}
	w.config.driver = _tx.drv
	return w
}

// String implements the fmt.Stringer.
func (w *Weather) String() string {
	var builder strings.Builder
	builder.WriteString("Weather(")
	builder.WriteString(fmt.Sprintf("id=%v, ", w.ID))
	builder.WriteString("temperature=")
	builder.WriteString(fmt.Sprintf("%v", w.Temperature))
	builder.WriteString(", ")
	builder.WriteString("humidity=")
	builder.WriteString(fmt.Sprintf("%v", w.Humidity))
	builder.WriteString(", ")
	builder.WriteString("windSpeed=")
	builder.WriteString(fmt.Sprintf("%v", w.WindSpeed))
	builder.WriteString(", ")
	builder.WriteString("weatherCondition=")
	builder.WriteString(fmt.Sprintf("%v", w.WeatherCondition))
	builder.WriteString(", ")
	builder.WriteString("precipitationAmount=")
	builder.WriteString(fmt.Sprintf("%v", w.PrecipitationAmount))
	builder.WriteString(", ")
	builder.WriteString("measurementDateTime=")
	builder.WriteString(w.MeasurementDateTime.Format(time.ANSIC))
	builder.WriteByte(')')
	return builder.String()
}

// Weathers is a parsable slice of Weather.
type Weathers []*Weather
